<?php
class DomenyModel{	
	const driver = "sqlite";
	
	protected function dodajDomeneDoBazy($user, $domena,$typ){
		global $parameters;
		if(is_file($parameters['sqlite']['host'].$domena.".db")) return false;
		$q__ = "SELECT domenaID FROM ".DOMENY." WHERE domenaID = ".tools::__mres($domena);
		if ($domena == tools::__adodb('getOne',$q__,true,$this->db,DomenyModel::driver) ) return false;
		$q__ = "INSERT INTO ".DOMENY." (userID, domenaID,data_rejestracji,data_zakonczenia,status_domeny,typ_domeny,abonament) 
			VALUES ('".$user->id."',".tools::__mres($domena).",'".date('Y-m-d H:i:s')."',
				'".date('Y-m-d H:i:s',mktime (date('H'),date('i'),date('s'),date('m'),  date('d'),  date('Y')+0))."','nieoplacona','$typ','{$this->abonament}')";
		return tools::__adodb('exec',$q__,true,$this->db,DomenyModel::driver);
	}
	
	protected function listaDomenUzytkownika($id){
		$q__ = "SELECT * FROM ".DOMENY." WHERE userID = '$id'";
		return tools::__adodb('getAll',$q__,true,$this->db,DomenyModel::driver);
	}
	
	protected function daneDomeny(){
		global $parameters;
		if(is_file($parameters['sqlite']['host'].$this->domena.".db")) return false;
		$q__ = "SELECT * FROM ".DOMENY." WHERE domenaID = ".tools::__mres($this->domena);
		return tools::__adodb('getRow',$q__,true,$this->db,DomenyModel::driver);
	}
	
	protected function usunDomene($domena){
		if(is_file($parameters['sqlite']['host'].$this->domena.".db")) return false;
		// mozna by zmieniac nazwe pliku lub kompresowac jako kopie
		
		$q__ = "DELETE FROM ".DOMENY." WHERE domenaID = ".tools::__mres($domena);
		return tools::__adodb('exec',$q__,true,$this->db,DomenyModel::driver);
	}
}
?>